home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / BISON-TC / MAIN.C < prev    next >
Text File  |  1989-12-30  |  3KB  |  141 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of Bison, the GNU Compiler Compiler.
  5.  
  6. Bison is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. Bison is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Bison; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "system.h"
  23. #include "machine.h"    /* JF for MAXSHORT */
  24.  
  25. #ifdef THINK_C
  26. #include <console.h>
  27. #endif
  28.  
  29. extern    int lineno;
  30. extern    int verboseflag;
  31.  
  32. /* Nonzero means failure has been detected; don't write a parser file.  */
  33. int failure;
  34.  
  35. extern void getargs(), openfiles(), reader(), reduce_grammar();
  36. extern void set_derives(), set_nullable(), generate_states();
  37. extern void lalr(), initialize_conflicts(), verbose(), terse();
  38. extern void output(), done(), abort();
  39.  
  40.  
  41. void
  42. main(argc, argv)
  43. int argc;
  44. char *argv[];
  45. {
  46.   failure = 0;
  47.   lineno = 0;
  48. #ifdef THINK_C
  49.     argc = ccommand (&argv);        /* simulate command-line arguments */
  50. #endif
  51.   getargs(argc, argv);
  52.   openfiles();
  53.  
  54.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  55.      In file reader.c.
  56.      The other parts are recorded in the grammar; see gram.h.  */
  57.   reader();
  58.  
  59.   /* find useless nonterminals and productions and reduce the grammar.  In
  60.      file reduce.c */
  61.   reduce_grammar();
  62.  
  63.   /* record other info about the grammar.  In files derives and nullable.  */
  64.   set_derives();
  65.   set_nullable();
  66.  
  67.   /* convert to nondeterministic finite state machine.  In file LR0.
  68.      See state.h for more info.  */
  69.   generate_states();
  70.  
  71.   /* make it deterministic.  In file lalr.  */
  72.   lalr();
  73.  
  74.   /* Find and record any conflicts: places where one token of lookahead is not
  75.      enough to disambiguate the parsing.  In file conflicts.
  76.      Currently this does not do anything to resolve them;
  77.      the trivial form of conflict resolution that exists is done in output.  */
  78.   initialize_conflicts();
  79.  
  80.   /* print information about results, if requested.  In file print. */
  81.   if (verboseflag)
  82.     verbose();
  83.   else
  84.     terse();
  85.  
  86.   /* output the tables and the parser to ftable.  In file output. */
  87.   output();
  88.   done(failure);
  89. }
  90.  
  91. /* functions to report errors which prevent a parser from being generated */
  92.  
  93. void
  94. fatal(s)
  95. char *s;
  96. {
  97.   extern char *infile;
  98.  
  99.   if (infile == 0)
  100.     fprintf(stderr, "fatal error: %s\n", s);
  101.   else
  102.     fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  103.   done(1);
  104. }
  105.  
  106.  
  107. /* JF changed to accept/deal with variable args.  Is a real kludge since
  108.    we don't support _doprnt calls */
  109. /*VARARGS1*/
  110.  
  111. void
  112. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  113. char *fmt;
  114. {
  115.   char buffer[200];
  116.  
  117.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  118.   fatal(buffer);
  119. }
  120.  
  121.  
  122. void
  123. toomany(s)
  124. char *s;
  125. {
  126.   char buffer[200];
  127.  
  128.     /* JF new msg */
  129.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  130.   fatal(buffer);
  131. }
  132.  
  133.  
  134. void
  135. berror(s)
  136. char *s;
  137. {
  138.   fprintf(stderr, "internal error, %s\n", s);
  139.   abort();
  140. }
  141.